package ija.view;

import ija.controller.CheckersController;
import ija.controller.GameController;
import ija.controller.MainController;
import ija.model.basis.Desk;
import ija.model.players.Player;

import java.util.Observable;
import java.util.Observer;

public class ReplayerContent extends BoardGameContent implements Observer {

	private static final long serialVersionUID = -6581640522193577439L;
	protected Desk dDesk;
	protected CheckersController controller;

	public ReplayerContent(MainController gc) {
		// this.setController(gc);
		// this.addWidgets(gc);
		this.getController().setView(this);
		// this.getController().getModel().addObserver(this);
		// this.getController().initModel(FigureColor.BLACK);
	}

	@Override
	protected void addWidgets(GameController gc) {
		super.addWidgets(gc);
		this.pPlayer1.addHostListener(this.controller.createHostListener());
		this.pPlayer1.addJoinListener(this.controller.createJoinListener());
		this.pPlayer2.addHostListener(this.controller.createHostListener());
		this.pPlayer2.addJoinListener(this.controller.createJoinListener());
	}

	public void setController(CheckersController gc) {
		this.controller = gc;
	}

	@Override
	public CheckersController getController() {
		return this.controller;
	}

	@Override
	public void update(Observable o, Object obj) {
		if (obj instanceof Player[]) {
			Player players[] = (Player[]) obj;
			if (players[0] != null) {
				this.pPlayer1.setFromPlayer(players[0]);
			}
			if (players[1] != null) {
				this.pPlayer2.setFromPlayer(players[1]);
			}
		}
	}
}
